package gateway.config.redisson;

import common.model.enums.ApplicationRunnerOrderEnum;
import common.service.RedissonCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 缓存
 *
 * @author 米泽鹏
 */
@Component
@Slf4j
public class CacheInitializer implements ApplicationRunner, Ordered {

	@Resource
	private RedissonCacheService redissonCacheService;

	@Override
	public void run(ApplicationArguments args) {
		redissonCacheService.cacheSysUser().throwExceptionIfFailed();
		redissonCacheService.cacheSysUserRole().throwExceptionIfFailed();
		redissonCacheService.cacheSysRole().throwExceptionIfFailed();
		redissonCacheService.cacheSysRoleAuthority().throwExceptionIfFailed();
		redissonCacheService.cacheSysAuthority().throwExceptionIfFailed();
		redissonCacheService.cacheSysBusinessCode().throwExceptionIfFailed();
	}

	@Override
	public int getOrder() {
		return ApplicationRunnerOrderEnum.CACHE_APPLICATION_RUNNER.getOrder();
	}

}
